package com.dt76.smallloanbackenduser.controller.yaozhao;

import com.dt76.smallloanbackenduser.pojo.yaozhao.UpcomingExpire;
import com.dt76.smallloanbackenduser.remote.yaozhao.UpcominngExpireRemote;
import com.dt76.smallloanbackenduser.utils.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/yz")
public class UpcomingExpireController {

//注入远程调用接口
    @Autowired
    private UpcominngExpireRemote upcominngExpireRemote;

    @RequestMapping("/qryAll")
    @ResponseBody
    public List<UpcomingExpire> qryAll(){
        return upcominngExpireRemote.qryAll();
    }

    @RequestMapping("/qryPageAll")
    public String qryPageAll(Model model, Integer currentPageNo,
                             @RequestParam(value = "userName",required = false)String userName,
                             @RequestParam(value = "phoneNumber",required = false)String phoneNumber,
                             @RequestParam(value = "loanId",required = false)String loanId,
                             @RequestParam(value = "ContractId",required = false)String ContractId){
        if (currentPageNo <= 0) {
            currentPageNo = 1;
        }
        //02.调用动态查询+分页查询接口
        String paramUserName = "";
        if(userName != null && !userName.equals("")){
            paramUserName = "%"+userName+"%";
        }
        String paramPhoneNumber = "";
        if(phoneNumber != null && !phoneNumber.equals("")){
            paramPhoneNumber = phoneNumber;
        }
        String paramloanId = "";
        if(loanId != null && !loanId.equals("")){
            paramloanId = loanId;
        }
        String paramContractId = "";
        if(ContractId != null && !ContractId.equals("")){
            paramContractId = ContractId;
        }
        Page page = upcominngExpireRemote.qryPageAll(currentPageNo,paramUserName,paramPhoneNumber,paramloanId,paramContractId);

        //03.组织返回值
        model.addAttribute("qryAllPageList",page.getRows());
        model.addAttribute("page",page);
        //加入动态查询条件返回
        model.addAttribute("userName",userName);
        model.addAttribute("phoneNumber",phoneNumber);
        model.addAttribute("loanId",loanId);
        model.addAttribute("ContractId",ContractId);
        return "/pages/yaozhao/UpcomingExpire";
    }

}

